package com.leetcode.partition5;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @author `RKC`
 * @date 2022/2/3 16:02
 */
public class LC499迷宫III {

    private static final int N = 35, M = 35, INF = 0x3f3f3f3f;
    private static final int[][] dirs = {{1, 0}, {0, -1}, {0, 1}, {-1, 0}};
    private static final char[] des = {'d', 'l', 'r', 'u'};
    private static int[][] graph, dist = new int[N][M];

    private static int n = 0, m = 0;
    private static PriorityQueue<Node> heap = new PriorityQueue<>(N * M, (o1, o2) -> o1.d == o2.d ? o1.path.compareTo(o2.path) : Integer.compare(o1.d, o2.d));

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), m = Integer.parseInt(ss[1]);
        ss = reader.readLine().split(" ");
        int[] start = {Integer.parseInt(ss[0]), Integer.parseInt(ss[1])}, end = {Integer.parseInt(ss[2]), Integer.parseInt(ss[3])};
        int[][] maze = new int[n][m];
        for (int i = 0; i < n; i++) {
            ss = reader.readLine().split(" ");
            for (int j = 0; j < m; j++) maze[i][j] = Integer.parseInt(ss[j]);
        }
        writer.write(findShortestWay(maze, start, end));
        writer.flush();
    }

    public static String findShortestWay(int[][] maze, int[] ball, int[] hole) {
        graph = maze;
        n = maze.length;
        m = maze[0].length;
        for (int i = 0; i < N; i++) Arrays.fill(dist[i], INF);
        dist[ball[0]][ball[1]] = 0;
        heap.add(new Node(ball[0], ball[1], 0, ""));
        while (!heap.isEmpty()) {
            Node cur = heap.poll();
            int x = cur.x, y = cur.y, d = cur.d;
            String path = cur.path;
            if (x == hole[0] && y == hole[1]) return path;
            for (int i = 0; i < dirs.length; i++) {
                int nx = x, ny = y, nd = d;
                while (check(nx + dirs[i][0], ny + dirs[i][1])) {
                    nx += dirs[i][0];
                    ny += dirs[i][1];
                    nd++;
                    if (nx == hole[0] && ny == hole[1]) break;
                }
                if (d < nd && nd <= dist[nx][ny]) {
                    dist[nx][ny] = nd;
                    heap.add(new Node(nx, ny, nd, path + des[i]));
                }
            }
        }
        return "impossible";
    }

    private static boolean check(int x, int y) {
        return 0 <= x && x < n && 0 <= y && y < m && graph[x][y] != 1;
    }

    private static class Node {
        private int x, y, d;
        private String path;

        public Node(int x, int y, int d, String path) {
            this.x = x;
            this.y = y;
            this.d = d;
            this.path = path;
        }
    }
}
